package com.ch.light.web.controller;

import com.ch.light.web.entity.pojo.MenuTitle;
import com.ch.light.web.model.Role;
import com.ch.light.web.service.MenuService;
import com.ch.light.web.util.UserContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private MenuService menuService;

    @GetMapping(value = {"/", "/index"})
    public String index(ModelMap modelMap) {
        String roleId = (String) UserContextUtil.getAttribute("roleId");
        String roleName = (String) UserContextUtil.getAttribute("roleName");
        List<MenuTitle> menuTitleList = menuService.getListByRoleId(roleId);

        modelMap.put("roleName", roleName);

        modelMap.put("menuList", menuTitleList);
        modelMap.put("roleMap", UserContextUtil.getAttribute("roleMap"));
        return "index";
    }
}
